#pragma once
#include "Shape.h"
#include "Intersection.h"
//#include "Scene.h"
#include "Ray.h"
#include "BBox.h"
#include <list>
using namespace std;

//#include "Ray.h"
//class Shape;
//#include "Intersection.h"
//

class Scene;

//#include <vector>


class BVHnode{
public:
	BVHnode();
	BVHnode(float _xmin, float _ymin, float _zmin, float _xmax, float _ymax, float _zmax);
	~BVHnode();

	bool build(list<Shape*> _li, int _groupSize);	//list of shape pointers that will belong to this node or to all of its combined descendants

	bool intersect(Ray *_theRay, float &_t0, float &_t1);		//whether a ray intersects this BVHnode
	void intersect(Intersection &_int);	//perform an intersection test on the BVHnode's contents

	BVHnode* left(){ return theLeft; }
	BVHnode* right(){ return theRight; }

	bool isLeaf(){ return thisIsLeaf; }
	int count(){ return theShapes.size(); }
	void scene(Scene *_s){ theScene = _s; }

	BBox boundingBox(){ return theBBox; }			//returns the bounding box for this node

private:
	BVHnode *theLeft;			//pointer to the 'left' node
	BVHnode *theRight;			//pointer to the 'right' node
	BVHnode *theParent;			//pointer to the parent node

	bool thisIsLeaf;			//whether this node is a leaf node, meaning it contains actual geometry

	//int itemCount;				//the number of Shape objects contained in this node

	int theSplitAxis;			//the axis on which this node is split

	Scene *theScene;			//pointer to the scene
	
	BBox theBBox;				//the bounding box

	list<Shape*> theShapes;	//a list of the shapes contained in this BBox
};

